<template>
<div>
	<Card>
		<p slot="title">企业信息</p>
		<div style="max-width:500px;">
			<Form :ref="formRef" :model="model" :label-width="100">
				<FormItem label="企业名称" prop="name" required>
					<Input v-model="model.name" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="企业电话" prop="phoneNumber" required>
					<Input v-model="model.phoneNumber" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="企业地址" prop="address">
					<Input v-model="model.address" type="textarea" :rows="3" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="工作时间" prop="workingDay">
					<Input v-model="model.workingDay" type="textarea" :rows="3" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="QQ" prop="qq">
					<Input v-model="model.qq" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="微博" prop="weibo">
					<Input v-model="model.weibo" :disabled="!isEditing" />
				</FormItem>
				<FormItem label="微信" prop="weixin">
					<picture-single v-model="model" prop="weixin" :height="100" :width="100" :disabled="!isEditing"></picture-single>
				</FormItem>
				<FormItem>
					<Button v-if="isEditing" type="primary" @click="handleSave" mgr2>保存修改</Button>
					<Button v-if="isEditing" @click="handleCancel">取消</Button>
					<Button v-if="!isEditing" type="primary" @click="isEditing=true">编辑</Button>
				</FormItem>
			</Form>
		</div>
	</Card>
</div>
</template>

<script lang="ts">
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';
import AbpBase from '../../lib/abpbase'
import PictureSingle from '@common/components/picture-single.vue'

@Component({
	components: { PictureSingle }
})
export default class ColumnArticleManager extends AbpBase{
	isEditing:boolean = false;
	showModal:boolean=false;
	formRef:string = this.getRandomRef('friendlylink-form')
	model:any = this.getDefaultModel()

	getDefaultModel() {
		return {
			name: "",
			phoneNumber: "",
			address: "",
			qq: "",
			weixin: "",
			weibo: "",
			workingDay: ""
		}
	}
	async handleCancel() {
		await this.handleGetData();
		this.isEditing = false;
	}
	async handleSave() {
		(this.$refs[this.formRef] as any).validate( async (valid) => {
			if(valid) {
				var response = await this.post('WebsiteInfo/SetCompanyInfo', this.model);
				if(response.success) {
					this.isEditing = false;
				}
			}
		});
	}
	async handleGetData() {
		var response = await this.get('WebsiteInfo/GetCompanyInfo');
		if(response.success) {
			this.model = response.result;
		}
	}
	async created() {
		await this.handleGetData();
	}
}
</script>